<template>
    <div class="wrapper">
        <HeaderNav title="orderDetail"></HeaderNav>
        <div class="flow_images">
            <div class="cart_images">
                <div class="cartItem" :style="{opacity:order.status=='没付款'?1:0}">
                    <img src="https://m.diyeetech.com/static/order/cart.png" alt="">
                </div>
                <div class="cartItem" :style="{opacity:order.status=='已付款'?1:0}">
                    <img src="https://m.diyeetech.com/static/order/cart.png" alt="">
                </div>
                <div class="cartItem" :style="{opacity:order.status=='未发货'?1:0}">
                    <img src="https://m.diyeetech.com/static/order/cart.png" alt="">
                </div>
                <div class="cartItem" :style="{opacity:order.status=='已发货'?1:0}">
                    <img src="https://m.diyeetech.com/static/order/cart.png" alt="">
                </div>
            </div>
            <div class="line"></div>
            <div class="text_flows">
                <div class="text_item">
                    <div class="span">未付款</div>
                    <Svgicon icon="icon-right1"></Svgicon>
                </div>
                <div class="text_item">
                    <div class="span">已付款</div>
                    <Svgicon icon="icon-right1"></Svgicon>
                </div>
                <div class="text_item">
                    <div class="span">未发货</div>
                    <Svgicon icon="icon-right1"></Svgicon>
                </div>
                <div class="text_item">
                    <div class="span">已发货</div>
                </div>
            </div>
        </div>
        <div class="plus_profile" style="margin-bottom: 5px">
            <span>订单编号：{{order.objectId}}</span>
            <span>日期：{{G.date.formatDateTime(order.createdAt)}}</span>
        </div>
        <AddressItem></AddressItem>

        <div class="orderitems">
            <OrderItem :item="item" v-for="item in orders"></OrderItem>
        </div>
        <div class="bottom">
            <div class="pay_item_wrapper" v-if="order.status=='未付款'">
                <div class="pay_item">
                    <div class="pay_check">
                        <input type="radio" name="pay" value="支付宝"
                               :checked="index_checked=='支付宝'"
                               @change="changeChecked('支付宝')"
                        ></input>
                        <div class="text"> 支付宝</div>
                    </div>
                </div>
                <div class="pay_item">
                    <div class="pay_check">
                        <input type="radio" name="pay" value="微信"
                               :checked="index_checked=='微信'"
                               @change="changeChecked('微信')"
                        ></input>
                        <div class="text"> 微信</div>
                    </div>
                </div>
                <div class="pay_item">
                    <div class="pay_check">
                        <input type="radio" name="pay" value="定易"
                               :checked="index_checked=='定易'"
                               @change="changeChecked('定易')"
                        ></input>
                        <div class="text"> 定易</div>
                    </div>
                </div>
            </div>

            <div class="price_buy_order">
                <div class="label">总计：
                    <strong>￥{{totalPrice}}</strong>
                </div>
                <div class="wrapp_buy_it_button" v-if="order.status=='未付款'">
                    <div class="buy_it_button" @click="mackOrder"> 立即购买</div>
                </div>
            </div>

        </div>
    </div>
</template>
<script>
    import HeaderNav from '../../components/HeaderNav'
    import Svgicon from '../../components/svgIcon'
    import AddressItem from './addressItem'
    import OrderItem from './orderItem'
    import withStore from "../../vuex/withStore";
    import {getOrder} from "../order/service";
    import myalert from '../../utils/myalert'
    import {setLocal} from "../../utils/local";
    import {pay_order} from "./service";

    export default withStore({
        components: {
            HeaderNav, Svgicon, AddressItem, OrderItem
        },
        computed:{
            totalPrice() {
                var price = 0;
                this.orders.map(item => {
                    price += item.unitPrice * item.quantity
                })
                return price
            }
        },
        data() {
            return {
                index_checked: '定易',
                order: {
                    status: "未付款"
                },
                orders: []
            }
        },
        mounted() {
            var self = this
            var orderId = this.$route.params.id
            getOrder(orderId).then(({orders, order}) => {
                self.setStore("order.orders", orders)
                self.setStore("order.order", order)
                self.orders = orders
                self.order = order
            })
        },
        methods: {
            changeChecked(item) {
                this.index_checked = item
            },
            mackOrder() {
                var orderId = this.$route.params.id
                var self = this
                if (this.index_checked != '定易') {
                    myalert.fail("不支持此类型支付")
                    return false
                }
                myalert.loading()
                myalert.confirm().then(res => {
                    pay_order(orderId).then((order) => {
                        myalert.clear()
                        self.setStore("order.order", order)
                        self.order = order
                    })
                })

            }
        }
    })
</script>
<style lang="less" scoped>
    .wrapper {
        .plus_profile {
            width: 100%;
            overflow: hidden;
            margin-top: 10px;
            display: flex;
            justify-content: space-between;
            padding-left: px2rem(20);
            padding-right: px2rem(20);
        }
        .flow_images {
            background: orange;
            height: 100px;
            .cart_images {
                display: flex;
                .cartItem {
                    height: 25px;
                    width: 80px;
                    position: relative;
                    left: 20px;
                    top: 20px;
                    img {
                        max-width: 100%;
                        max-height: 100%;
                    }
                    &:last-child {
                        width: 50px;
                    }
                }
            }
            .text_flows {
                display: flex;
                .text_item {
                    height: 25px;
                    width: 80px;
                    position: relative;
                    left: 20px;
                    top: 20px;
                    display: flex;
                    align-items: center;
                    color: #fff;
                    .span {
                        width: 50px;
                    }
                    &:last-child {
                        width: 50px;
                    }
                }
            }
            .line {
                height: 10px;
                width: 300px;
                background: url("https://m.diyeetech.com/static/order/road.png");
                background-size: 100% 100%;
                position: relative;
                top: 20px;
                left: 10px;
            }

        }

        .bottom {
            padding-left: px2rem(20);
            padding-right: px2rem(20);
            padding-top: px2rem(20);
            padding-bottom: px2rem(20);
            position: fixed;
            bottom: 0;
            left: 0;
            max-width: 750px;
            width: 100%;
            border-top: 1px solid #eee;
            .pay_item_wrapper {
                display: flex;
                .pay_item {
                    margin-right: 10px;
                }
                .pay_check {
                    display: flex;
                }
                margin-bottom: 5px;
            }

            .price_buy_order {

                display: flex;
                align-items: center;
                .label {
                    flex: 1;
                }
                .wrapp_buy_it_button {
                    .buy_it_button {
                        color: #fff;
                        cursor: pointer;
                        text-align: center;
                        display: flex;
                        justify-content: center;
                        align-self: center;
                        align-items: center;
                        width: 2rem;
                        height: .36rem;
                        border-radius: 20px;
                        background-image: linear-gradient(90deg, #ff4e00, red);
                    }
                }
            }
        }
    }
</style>